package com.taobao.vsearch;

import org.apache.solr.common.SolrInputDocument;

import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: caoling
 * Date: 11-3-14
 * Time: 1:51 pm
 * To change this template use File | Settings | File Templates.
 */
public class DocBuilder {

    public static final String DOC_BOOST = "$docBoost";
    public static final String SKIP_DOC = "$skipDoc";

    /**
     * @param row
     * @param row
      * @return
     */
    public static SolrInputDocument toSolrInputDocument(Map<String, Object> row) {
//        Object skip = row.remove(SKIP_DOC);
//        if (skip != null) {
//            return null;
//        }
        SolrInputDocument doc = new SolrInputDocument();
//        Object boost = row.remove(DOC_BOOST);
//        if (boost != null) {
//            if (boost instanceof Float || boost instanceof Double) {
//                doc.setDocumentBoost((Float) boost);
//            } else {
//                try {
//                    float b = Float.parseFloat(boost.toString());
//                    doc.setDocumentBoost(b);
//                } catch (NumberFormatException e) {
//                    // eat...
//                }
//            }
//        }

        for (String key : row.keySet()) {
            doc.addField(key, row.get(key), 1.0f);
        }

        return doc;
    }
}
